import 'dart:isolate';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/*
 * @Author: zhudaihao
 * @Date: 2022/3/4
 * @Describe:
 */

///
class Test2 extends StatefulWidget {
  const Test2({Key? key}) : super(key: key);

  @override
  State<Test2> createState() => _Test2State();
}

class _Test2State extends State<Test2> {
  String ?tag = "点击";


  @override
  Widget build(BuildContext context) {
    return Scaffold(

    
      appBar: AppBar(
        title: const Text("tes2"),
      ),
      body: GestureDetector(
        onTap: () {
          setState(() {
            tag = (tag == "点击" ? "更新点击" : "点击");
          });
        },
        child: Column(
          children: [
            SizedBox(
              child: Image.asset("assets/images/area1.png"),
              width: 200,
              height: 200,
            ),
            SizedBox(
              child: Image.asset("assets/images/area1.png"),
              width: 200,
              height: 200,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children:  [
                ElevatedButton(
                    onPressed: () {
                      setState(() {
                        tag = (tag == "点击" ? "更新点击" : "点击");
                      });
                    },
                    child: Text(tag??"点击")),

                //  MyButton(
                //   onPressed: () {
                //     setState(() {
                //       tag = (tag == "点击" ? "更新点击" : "点击");
                //     });
                //   },
                //   child: Text(tag??"点击"),
                //   color: Colors.blue,
                // ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

///

// class Test2 extends StatelessWidget {
//   const Test2({Key? key}) : super(key: key);
//
//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(
//         title: const Text("test2"),
//       ),
//       body: Column(
//         children: [
//           Image.asset(
//             "assets/images/area1.png",
//             width: 200,
//             height: 200,
//           ),
//           Image.asset(
//             "assets/images/area1.png",
//             width: 200,
//             height: 200,
//           ),
//
//
//           const MyNewButton(),
//
//       // MyButton(
//       //     onPressed: () {
//       //       setState(() {
//       //         // tag = !tag!;
//       //       });
//       //     },
//       //     child: const Text("更新13"),color: Colors.blue,)
//         ],
//       ),
//     );
//   }
// }

class MyNewButton extends StatefulWidget {
  const MyNewButton({Key? key}) : super(key: key);

  @override
  _MyNewButtonState createState() => _MyNewButtonState();
}

class _MyNewButtonState extends State<MyNewButton> {
  bool? tag = false;

  @override
  Widget build(BuildContext context) {
    // return ElevatedButton(
    //     onPressed: () {
    //       // setState(() {
    //       //   // tag = !tag!;
    //       // });
    //     },
    //     child: const Text("更新11"));

    return MyButton(
      key: const ObjectKey("MyButton"),
      onPressed: () {
        setState(() {

        });
      },
      child: const Text("更新12"),
      color: Colors.blue,
    );
  }
}

class MyButton extends StatelessWidget {
  final Widget? child;
  final Color? color;
  final Function()? onPressed;
  final double? width;
  final double? height;
  final double? circular;

  const MyButton(
      {Key? key,
      this.onPressed,
      this.child,
      this.color,
      this.width,
      this.height,
      this.circular})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        alignment: Alignment.center,
        width: width ?? 86,
        height: height ?? 36,
        child: child,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(circular ?? 2),
          color: color,
        ),
      ),
      onTap: () {
        if (onPressed != null) {
          onPressed!();
        }
      },
    );
  }
}
